package it.koutifaris.travianmap.ui.drawhelpers.village;

import it.koutifaris.travianmap.ui.PointToSquareHelper;
import it.koutifaris.travianmap.ui.viewstate.DynamicViewState;
import android.graphics.Canvas;

abstract class AbstractVillageDrawer implements VillageDrawer {

	private DynamicViewState viewState;
	private Canvas canvas;
	private final PointToSquareHelper pointToSquareHelper;

	public AbstractVillageDrawer(PointToSquareHelper pointToSquareHelper) {
		this.pointToSquareHelper = pointToSquareHelper;
	}

	@Override
	public void setup(Canvas canvas, DynamicViewState viewState) {
		this.canvas = canvas;
		this.viewState = viewState;
	}

	protected DynamicViewState getViewState() {
		return viewState;
	}

	protected Canvas getCanvas() {
		return canvas;
	}

	protected PointToSquareHelper getPointToSquareHelper() {
		return pointToSquareHelper;
	}

	protected int getXInViewPort(int x) {
		return getPointToSquareHelper().getSquareCorner(x) - getViewState().getX();
	}

	protected int getYInViewPort(int y) {
		return getPointToSquareHelper().getSquareCorner(y) - getViewState().getY();
	}
}
